<?php 
namespace lib\protocol;
class WxUos{
    protected $api;
    public function __construct($api = null){
        $this->api = empty($api) ? 'http://uosapi.daoh.top':$api;
    }
    public function wxlogin(){
        $api  = $this->api.'/api/GetLoginData';
        
        $res  = json_decode(get_curl($api),true);
        if($res['uuid']){
            return ['uuid'=>$res['uuid'] , 'id'=>$res['uuid'],'qr_url'=>$res['qr_url']];
        }
        return ['code'=>-1,'msg'=>'未知错误'];
    }
    public  function wxCheckLoginQrcode($guid, $uuid){
        $api  = $this->api.'/api/CheckLoginState';
        $post = array(
            'uuid'=>$uuid
        );
        $res  = json_decode(get_curl($api,$post),true);
        if($res['code'] == 2){
            $result = ["code" => 2, "msg" => "等待确认中"];
        }else if($res['code'] == 500){
            $result = ["code" => -1, "msg" => "已取消", "state" => $res["data"]["state"]];
        }else if($res['code'] == 200 && $res['buid']){
            $result = ["code" => 0, "msg" => "登录成功", "cookie" => $res['buid']];
        }else{
            $result = ["code"=>1];
        }
        return $result;
    }
    public function WXHeartBeat($cookie){
        $api  = $this->api.'/api/GetMessage';
        $post = array(
            'buid'=>$cookie
            );
        $res = json_decode(get_curl($api,$post),true);
        if($res['data']){
    	 	 $result = ["code" => 1, "msg" => "心跳正常"];
	 	}else{
	 	     $result = ["code" => -1, "msg" => "账户已经离线"];
	 	}
	 	return $result;
        
    }
}
?>